// Package service /*
package service

import (
	cf "godocker/common/functions"
)

type mongo struct {
	SName string

	basicDir []string
	name     string
	user     string
	pwd      string
	version  string
}

func mongoNew() *mongo {
	i := installDir + "/lib/mongo"
	return &mongo{
		"mongo",
		[]string{
			i + "/data",
		},
		cf.GetEnvVal(installDir+"/.env", "mgoname="),
		cf.GetEnvVal(installDir+"/.env", "mgouser="),
		cf.GetEnvVal(installDir+"/.env", "mgopwd="),
		cf.GetEnvVal(installDir+"/.env", "mgov="),
	}
}

func (m mongo) install() {
	m.mkdir()
	m.dockerPull()
}

func (m mongo) mkdir() {
	for _, v := range m.basicDir {
		cf.MakeDir(v)
	}
}

func (m mongo) dockerPull() {
	cf.ExecShell("docker run --name " + m.name + " -dp 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=" + m.user + " -e MONGO_INITDB_ROOT_PASSWORD=" + m.pwd + " mongo:" + m.version)

	cf.ExecShell("docker cp " + m.name + ":/data/db/. " + m.basicDir[0])

	cf.ExecShell("docker stop " + m.name)

	cf.ExecShell("docker rm " + m.name)
}
